﻿using System;
using Microsoft.SharePoint;

namespace LifeInSharePoint.Metro.Common.Branding.LifeInSharePoint.Metro
{
    using Microsoft.SharePoint.Utilities;

    public class WebEventReceiver : SPWebEventReceiver
    {
        string masterUrl = "LifeInSharePoint.master";
        string searchMasterUrl = "LifeInSharePointSearch.master";
        public override void WebProvisioned(SPWebEventProperties properties)
        {
            SPWeb web = properties.Web;
            SPWeb siteCollection = web.Site.RootWeb;

            masterUrl = SPUrlUtility.CombineUrl(siteCollection.ServerRelativeUrl,
                "_catalogs/masterpage/" + masterUrl);

            searchMasterUrl = SPUrlUtility.CombineUrl(siteCollection.ServerRelativeUrl,
                "_catalogs/masterpage/" + searchMasterUrl);

            if (web.WebTemplate == "SRCHCENTERLITE" || web.WebTemplate == "SRCHCEN" || web.WebTemplate == "SRCHCENTERFAST")
            {
                web.MasterUrl = masterUrl;
                web.CustomMasterUrl = searchMasterUrl;
            }

            else
            {
                web.MasterUrl = masterUrl;
                web.CustomMasterUrl = masterUrl;
            }
            web.Update();
        }
    }
}